package com.hzxy.yiyid.web.module.controller;

import com.hzxy.yiyid.web.common.base.BaseResult;
import com.hzxy.yiyid.web.common.error.ErrorCodeEnum;
import com.hzxy.yiyid.web.module.controller.Dto.ArticleInfo;
import com.hzxy.yiyid.web.module.controller.Dto.ClassfyName;
import com.hzxy.yiyid.web.module.service.MessageArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Api(tags = "文章相关接口")
public class AtricleController {

    private static final Logger logger = LoggerFactory.getLogger(AtricleController.class);

    @Autowired
    private MessageArticleService messageArticleService;

    /**
     * 通过知识类别拿到科普id再去找到所有符合该id的所有数据
     * @param classfyId
     * @return
     */

    @GetMapping("/getScienceKnowleges/{classfyId}")
    @ApiOperation(value ="通过分类文字名称获取分类id在获取所有该分类下的文章" ,notes = "通过分类文字名称获取分类id在获取所有该分类下的文章")
    public BaseResult<?> getAllfirstAid(@PathVariable("classfyId") Integer classfyId){
        if(StringUtils.isBlank(classfyId.toString())){
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(), ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(), ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
        }
        return messageArticleService.getClassfyId(classfyId);
    }


    /**
     * 通过传进来的文章id和分类科普id获取详细信息
     * @param id
     * @param scienceId
     * @return
     */
    @GetMapping("/getScienceKnowleges/articleDetails")
    @ApiOperation(value ="通过上传文字id和分类id获取详细信息" ,notes = "通过上传文字id和分类id获取详细信息" )
    public BaseResult<?> getArticleDetails(@RequestParam Integer id, Integer scienceId) {
        if (StringUtils.isBlank(id.toString()) || StringUtils.isBlank(scienceId.toString())) {
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
        }
        return messageArticleService.getArticleDetails(id,scienceId);
    }


}

